﻿using System;
using System.Collections.Generic;
using System.Text;
using Mono.Cecil;
using Mono.Cecil.Cil;
using ProjScan.Modules;
using ProjScan.Tools;

namespace ProjScan.Submodules.CS_Check
{
	// Token: 0x0200019D RID: 413
	internal class LineMapping
	{
		// Token: 0x06000DF2 RID: 3570 RVA: 0x0003F070 File Offset: 0x0003D270
		public void Merge(LineMapping incomingLineMapping)
		{
			bool flag = incomingLineMapping != null;
			if (flag)
			{
				foreach (KeyValuePair<string, HashSet<int>> keyValuePair in incomingLineMapping.lineMappingDictionary)
				{
					foreach (int startLine in keyValuePair.Value)
					{
						this.AddMapping(keyValuePair.Key, startLine);
					}
				}
			}
		}

		// Token: 0x06000DF3 RID: 3571 RVA: 0x0003F11C File Offset: 0x0003D31C
		public void AddMapping(string absolutePath, int startLine)
		{
			string key = ToolsHelper.ConvertAbsolutePathToRelative(absolutePath);
			bool flag = !this.lineMappingDictionary.ContainsKey(key);
			if (flag)
			{
				this.lineMappingDictionary.Add(key, new HashSet<int>());
			}
			this.lineMappingDictionary[key].Add(startLine);
		}

		// Token: 0x06000DF4 RID: 3572 RVA: 0x0003F16C File Offset: 0x0003D36C
		public static LineMapping GetMapping(MethodDefinition methodDefinition, Instruction instruction)
		{
			SequencePoint sequencePoint = null;
			for (Instruction instruction2 = instruction; instruction2 != null; instruction2 = instruction2.Previous)
			{
				sequencePoint = methodDefinition.DebugInformation.GetSequencePoint(instruction2);
				bool flag = sequencePoint != null;
				if (flag)
				{
					break;
				}
			}
			bool flag2 = sequencePoint == null;
			LineMapping result;
			if (flag2)
			{
				ScanLog.Instance.LogInfo(Module.CS_Check, "Sequence Point is null");
				result = null;
			}
			else
			{
				LineMapping lineMapping = new LineMapping();
				lineMapping.AddMapping(sequencePoint.Document.Url.Replace("\\", "/"), sequencePoint.StartLine);
				result = lineMapping;
			}
			return result;
		}

		// Token: 0x06000DF5 RID: 3573 RVA: 0x0003F200 File Offset: 0x0003D400
		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (KeyValuePair<string, HashSet<int>> keyValuePair in this.lineMappingDictionary)
			{
				stringBuilder.Append(keyValuePair.Key);
				stringBuilder.Append(":");
				bool flag = true;
				foreach (int value in keyValuePair.Value)
				{
					bool flag2 = flag;
					if (flag2)
					{
						flag = false;
					}
					else
					{
						stringBuilder.Append(",");
					}
					stringBuilder.Append(value);
				}
				stringBuilder.Append(";");
			}
			return stringBuilder.ToString();
		}

		// Token: 0x040008BD RID: 2237
		private Dictionary<string, HashSet<int>> lineMappingDictionary = new Dictionary<string, HashSet<int>>();
	}
}
